<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>循环精灵图</title>
    <style>
        div {
            width: 300px;
            margin: 10px auto;
        }

        li {
            float: left;
            list-style: none;
            width: 24px;
            height: 24px;
            margin: 15px;
            background: url(images/sprite.png) no-repeat;
        }
    </style>
</head>

<body>
    <div>
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script>
        var li = document.querySelectorAll('li');
        for (var i = 0; i < li.length; i++) {
            var index = i * 44;
            li[i].style.backgroundPosition = '0 -' + index + 'px';
        }
        var li = document.querySelectorAll('li');
        for (var i = 0; i < li.length; i++) {
            var index = -i * 44;
            li[i].style.backgroundPosition = '0 ' + index + 'px';
        }
    </script>
</body>

</html>